<html lang="fr">
    <body>
    <div id="categorie">
        <ul id="menu-cat">
            <?php
                $textHTML = "";
                $i = 0;

                foreach (VariablesGlobales::$lesCategories as $uneCategorie){
                    if ((strpos(strtolower(VariablesGlobales::$lesCategories[$i]->libelle), " ") == true)){
                        $urlActionSplit = explode(" ", strtolower(VariablesGlobales::$lesCategories[$i]->libelle));
                        $j = 0;
                        $MyUrlCat = "";
                        foreach ($urlActionSplit as $urlAction){
                            if (count($urlAction) > 0){
                                if ($j != count($urlAction)){
                                    $MyUrlCat .= $urlAction . "%20";
                                }else{
                                    $MyUrlCat .= $urlAction;
                                }
                            }else{
                                $MyUrlCat .= $urlAction;
                            }
                            $j ++;
                        }
                    }elseif ((strpos(strtolower(VariablesGlobales::$lesCategories[$i]->libelle), "'") == true)){
                        $urlActionSplit = explode("'", strtolower(VariablesGlobales::$lesCategories[$i]->libelle));
                        $j = 0;
                        $MyUrlCat = "";
                        foreach ($urlActionSplit as $urlAction){
                            if (count($urlAction) > 0){
                                if ($j != count($urlAction)){
                                    $MyUrlCat .= $urlAction . "%27";
                                }else{
                                    $MyUrlCat .= $urlAction;
                                }
                            }else{
                                $MyUrlCat .= $urlAction;
                            }
                            $j ++;
                        }
                    }else{
                        $MyUrlCat = strtolower(VariablesGlobales::$lesCategories[$i]->libelle);
                    }
                    $textHTML .= "<li><a href='index.php?controleur=Boutique&action=Afficher&categorie=$MyUrlCat'>" . VariablesGlobales::$lesCategories[$i]->libelle . "</a>";
                    $souscat = ModeleBoutique::getLesSousCategoriesByCategorie(VariablesGlobales::$lesCategories[$i]->id);
                    $textHTML .= "<ul>";
                    foreach ($souscat as $uneSousCat) {
                        $rawurlencode = rawurlencode(strtolower($uneSousCat->libelle)); //TODO adapter le code avec l'utilisation de cette fonction
                        $MyUrlSousCat = "";
                        if ((strpos($uneSousCat->libelle, " ")) == true){
                            $urlSplit = explode(" ", strtolower($uneSousCat->libelle));
                            $j = 1;
                            foreach ($urlSplit as $strSplit){
                                if (count($urlSplit) > 0){
                                    if ($j != count($urlSplit)){
                                        $MyUrlSousCat .= $strSplit . "%20";
                                    }else{
                                        $MyUrlSousCat .= $strSplit;
                                    }
                                }else{
                                    $MyUrlSousCat .= $strSplit;
                                }
                                $j++;
                            }
                        }elseif ((strpos($uneSousCat->libelle, "'")) == true){
                            $urlSplit = explode("'", strtolower($uneSousCat->libelle));
                            $j = 1;
                            foreach ($urlSplit as $strSplit){
                                if (count($urlSplit) > 0){
                                    if ($j != count($urlSplit)){
                                        $MyUrlSousCat .= $strSplit . "%27";
                                    }else{
                                        $MyUrlSousCat .= $strSplit;
                                    }
                                }else{
                                    $MyUrlSousCat .= $strSplit;
                                }
                                $j++;
                            }
                        }else{
                            $MyUrlSousCat = $uneSousCat->libelle;
                        }

                        $textHTML .= "<li><a href='index.php?controleur=Boutique&action=AfficherSousCat&categorie=$MyUrlCat&souscategorie=$MyUrlSousCat'>" . $uneSousCat->libelle . "</a></li>";
                    }
                    $textHTML .= "</ul></li>";
                    $i++;
                }
                echo $textHTML;
            ?>
        </ul>
    </div>